package org.liveboardgames.agricola.control.delegates.mock.cards.majorimprovements
{
    import mx.collections.ArrayCollection;
    
    import org.liveboardgames.agricola.control.delegates.mock.ActionFactory;
    import org.liveboardgames.agricola.model.enums.ActionTempoEnum;
    import org.liveboardgames.agricola.model.enums.AlternativeCostEnum;
    import org.liveboardgames.agricola.model.enums.ImprovementTypeEnum;
    import org.liveboardgames.agricola.model.enums.ResourceTypeEnum;
    import org.liveboardgames.agricola.model.enums.RoundOffsetTypeEnum;
    import org.liveboardgames.agricola.model.enums.SpecialPointConditionEnum;
    import org.liveboardgames.agricola.view.component.ImageHandler;
    import org.liveboardgames.agricola.vo.action.Action;
    import org.liveboardgames.agricola.vo.action.ResourceTransformationAction;
    import org.liveboardgames.agricola.vo.card.BakingImprovementCard;
    import org.liveboardgames.agricola.vo.card.CookingImprovementCard;
    import org.liveboardgames.agricola.vo.card.ImprovementCard;
    import org.liveboardgames.agricola.vo.card.ResourceTransformation;
    import org.liveboardgames.agricola.vo.card.SpecialPoint;
    import org.liveboardgames.common.dictionary.collections.HashCollection;
    import org.liveboardgames.common.dictionary.collections.IMap;
    
    public class MajorImprovementCards
    {
        public static const FIREPLACE_CHEAP:ImprovementCard = getCheapFireplace();
        
        public static const FIREPLACE:ImprovementCard = getFireplace();
        
        public static const COOKING_HEARTH_CHEAP:ImprovementCard = getCheapCookingHearth();
        
        public static const COOKING_HEARTH:ImprovementCard = getCookingHearth();
        
        public static const CLAY_OVEN:ImprovementCard = getClayOven();
        
        public static const STONE_OVEN:ImprovementCard = getStoneOven();
        
        public static const WELL:ImprovementCard = getWell();
        
        public static const BASKETMAKER_WORKSHOP:ImprovementCard = getBasketmakerWorkshop();
        
        public static const JOINERY:ImprovementCard = getJoinery();
        
        public static const POTTERY:ImprovementCard = getPottery();
        
        public static function getCheapFireplace():ImprovementCard
        {
            var card:CookingImprovementCard = new CookingImprovementCard(2, 2, 2, 3, 2);
            card.cardName = "Cheap Fireplace";
            card.imagePath = ImageHandler.MAJOR_IMPROVEMENTS + "Fireplace1.png";
            card.addType(ImprovementTypeEnum.FIREPLACE);
            
            // Cost to build the card
            var cost:IMap = new HashCollection();
            cost.put(ResourceTypeEnum.CLAY, 2);
            card.cost = cost;
            
            // Number of points the card is worth
            card.points = 1;
            
            return card;
        }
        
        public static function getFireplace():ImprovementCard
        {
            var card:CookingImprovementCard = new CookingImprovementCard(2, 2, 2, 3, 2);
            card.cardName = "Fireplace";
            card.imagePath = ImageHandler.MAJOR_IMPROVEMENTS + "Fireplace2.png";
            card.addType(ImprovementTypeEnum.FIREPLACE);
            
            // Cost to build the card
            var cost:IMap = new HashCollection();
            cost.put(ResourceTypeEnum.CLAY, 3);
            card.cost = cost;
            
            // Number of points the card is worth
            card.points = 1;
            
            return card;
        }
        
        public static function getCheapCookingHearth():ImprovementCard
        {
            var card:CookingImprovementCard = new CookingImprovementCard(3, 2, 3, 4, 3);
            card.cardName = "Cheap Cooking Hearth";
            card.imagePath = ImageHandler.MAJOR_IMPROVEMENTS + "CookingHearth1.png";
            
            // Cost to build the card
            var cost:IMap = new HashCollection();
            cost.put(ResourceTypeEnum.CLAY, 4);
            card.cost = cost;
            
            // Alternative cost: discard a fireplace
            var alternativeCost:IMap = new HashCollection();
            alternativeCost.put(AlternativeCostEnum.DISCARD_FIREPLACE, 1);
            card.addAlternativeCost(alternativeCost);
            
            // Number of points the card is worth
            card.points = 1;
            
            return card;
        }
        
        public static function getCookingHearth():ImprovementCard
        {
            var card:CookingImprovementCard = new CookingImprovementCard(3, 2, 3, 4, 3);
            card.cardName = "Cooking Hearth";
            card.imagePath = ImageHandler.MAJOR_IMPROVEMENTS + "CookingHearth2.png";
            
            // Cost to build the card
            var cost:IMap = new HashCollection();
            cost.put(ResourceTypeEnum.CLAY, 5);
            card.cost = cost;
            
            // Alternative cost: discard a fireplace
            var alternativeCost:IMap = new HashCollection();
            alternativeCost.put(AlternativeCostEnum.DISCARD_FIREPLACE, 1);
            card.addAlternativeCost(alternativeCost);
            
            // Number of points the card is worth
            card.points = 1;
            
            return card;
        }
        
        public static function getClayOven():ImprovementCard
        {
            var card:BakingImprovementCard = new BakingImprovementCard(1, 5);
            card.cardName = "Clay Oven";
            card.imagePath = ImageHandler.MAJOR_IMPROVEMENTS + "ClayOven.png";
            
            // Cost to build the card
            var cost:IMap = new HashCollection();
            cost.put(ResourceTypeEnum.CLAY, 3);
            cost.put(ResourceTypeEnum.STONE, 1);
            card.cost = cost;
            
            // Number of points the card is worth
            card.points = 2;
            
            // When the card is bought, gain a free bake action
            var firstAction:Action = ActionFactory.getBakeAction();
            firstAction.tempo = ActionTempoEnum.PLAY_TRIGGERED;
            
            var actions:ArrayCollection = new ArrayCollection();
            actions.addItem(firstAction);
            card.actions = actions;
            
            return card;
        }
        
        public static function getStoneOven():ImprovementCard
        {
            var card:BakingImprovementCard = new BakingImprovementCard(2, 4);
            card.cardName = "Stone Oven";
            card.imagePath = ImageHandler.MAJOR_IMPROVEMENTS + "StoneOven.png";
            
            // Cost to build the card
            var cost:IMap = new HashCollection();
            cost.put(ResourceTypeEnum.CLAY, 1);
            cost.put(ResourceTypeEnum.STONE, 3);
            card.cost = cost;
            
            // Number of points the card is worth
            card.points = 3;
            
            // When the card is bought, gain a free bake action
            var firstAction:Action = ActionFactory.getBakeAction();
            firstAction.tempo = ActionTempoEnum.PLAY_TRIGGERED;
            
            var actions:ArrayCollection = new ArrayCollection();
            actions.addItem(firstAction);
            card.actions = actions;
            
            return card;
        }
        
        public static function getWell():ImprovementCard
        {
            var card:ImprovementCard = new ImprovementCard();
            card.cardName = "Well";
            card.imagePath = ImageHandler.MAJOR_IMPROVEMENTS + "Well.png";
            
            // Cost to build the card
            var cost:IMap = new HashCollection();
            cost.put(ResourceTypeEnum.WOOD, 1);
            cost.put(ResourceTypeEnum.STONE, 3);
            card.cost = cost;
            
            // Number of points the card is worth
            card.points = 4;
            
            // When the card is bought, put a food on each of the remaining rounds
            // The list of all rounds on which to put a food
            var roundNumbers:ArrayCollection = new ArrayCollection();
            roundNumbers.addItem(1);
            roundNumbers.addItem(2);
            roundNumbers.addItem(3);
            roundNumbers.addItem(4);
            roundNumbers.addItem(5);
            
            var putAction:Action = ActionFactory.getAddResourceOnBoardAction(ResourceTypeEnum.FOOD, roundNumbers, RoundOffsetTypeEnum.
                ADD, 1);
            putAction.tempo = ActionTempoEnum.PLAY_TRIGGERED;
            var takeAction:Action = ActionFactory.getTakeResourceOnBoardAction(ResourceTypeEnum.FOOD, roundNumbers, RoundOffsetTypeEnum.
                ADD, 1);
            var actions:ArrayCollection = new ArrayCollection();
            actions.addItem(putAction);
            actions.addItem(takeAction);
            
            card.actions = actions;
            
            return card;
        }
        
        public static function getBasketmakerWorkshop():ImprovementCard
        {
            var card:ImprovementCard = new ImprovementCard();
            card.cardName = "Basketmaker Workshop";
            card.imagePath = ImageHandler.MAJOR_IMPROVEMENTS + "BasketmakerWorkshop.png";
            
            // Cost to build the card
            var cost:IMap = new HashCollection();
            cost.put(ResourceTypeEnum.REED, 2);
            cost.put(ResourceTypeEnum.STONE, 2);
            card.cost = cost;
            
            // Number of points the card is worth
            card.points = 2;
            
            // Special points: all the special points will be taken into account. As such, 
            // if there are 5 reeds at the end of the game, the player will have 1 + 1 + 1 
            // points, which is what we want
            var specialPoint2:SpecialPoint = new SpecialPoint(SpecialPointConditionEnum.REED, 2, 1);
            var specialPoint4:SpecialPoint = new SpecialPoint(SpecialPointConditionEnum.REED, 4, 1);
            var specialPoint5:SpecialPoint = new SpecialPoint(SpecialPointConditionEnum.REED, 5, 1);
            card.addSpecialPoint(specialPoint2);
            card.addSpecialPoint(specialPoint4);
            card.addSpecialPoint(specialPoint5);
            
            // Once at harvest time, can use 1 reed to get 3 foods
            var reedTransformation:ResourceTransformation = new ResourceTransformation(ResourceTypeEnum.REED, ResourceTypeEnum.
                FOOD, 1, 3, 1);
            var possibleTransformations:ArrayCollection = new ArrayCollection();
            possibleTransformations.addItem(reedTransformation);
            
            var action:ResourceTransformationAction = ActionFactory.getResourceTransformationAction(possibleTransformations);
            action.tempo = ActionTempoEnum.HARVEST;
            
            var actions:ArrayCollection = new ArrayCollection();
            actions.addItem(action);
            card.actions = actions;
            
            return card;
        }
        
        public static function getJoinery():ImprovementCard
        {
            var card:ImprovementCard = new ImprovementCard();
            card.cardName = "Joinery";
            card.imagePath = ImageHandler.MAJOR_IMPROVEMENTS + "Joinery.png";
            
            // Cost to build the card
            var cost:IMap = new HashCollection();
            cost.put(ResourceTypeEnum.WOOD, 2);
            cost.put(ResourceTypeEnum.STONE, 2);
            card.cost = cost;
            
            // Number of points the card is worth
            card.points = 2;
            
            // Special points: all the special points will be taken into account. As such, 
            // if there are 5 reeds at the end of the game, the player will have 1 + 1 + 1 
            // points, which is what we want
            var specialPoint1:SpecialPoint = new SpecialPoint(SpecialPointConditionEnum.WOOD, 3, 1);
            var specialPoint2:SpecialPoint = new SpecialPoint(SpecialPointConditionEnum.WOOD, 5, 1);
            var specialPoint3:SpecialPoint = new SpecialPoint(SpecialPointConditionEnum.WOOD, 7, 1);
            card.addSpecialPoint(specialPoint1);
            card.addSpecialPoint(specialPoint2);
            card.addSpecialPoint(specialPoint3);
            
            // Once at harvest time, can use 1 wood to get 2 foods
            var transformation:ResourceTransformation = new ResourceTransformation(ResourceTypeEnum.WOOD, ResourceTypeEnum.
                FOOD, 1, 2, 1);
            var possibleTransformations:ArrayCollection = new ArrayCollection();
            possibleTransformations.addItem(transformation);
            
            var action:ResourceTransformationAction = ActionFactory.getResourceTransformationAction(possibleTransformations);
            action.tempo = ActionTempoEnum.HARVEST;
            
            var actions:ArrayCollection = new ArrayCollection();
            actions.addItem(action);
            card.actions = actions;
            
            return card;
        }
        
        public static function getPottery():ImprovementCard
        {
            var card:ImprovementCard = new ImprovementCard();
            card.cardName = "Pottery";
            card.imagePath = ImageHandler.MAJOR_IMPROVEMENTS + "Pottery.png";
            
            // Cost to build the card
            var cost:IMap = new HashCollection();
            cost.put(ResourceTypeEnum.CLAY, 2);
            cost.put(ResourceTypeEnum.STONE, 2);
            card.cost = cost;
            
            // Number of points the card is worth
            card.points = 2;
            
            // Special points: all the special points will be taken into account. As such, 
            // if there are 5 reeds at the end of the game, the player will have 1 + 1 + 1 
            // points, which is what we want
            var specialPoint1:SpecialPoint = new SpecialPoint(SpecialPointConditionEnum.CLAY, 3, 1);
            var specialPoint2:SpecialPoint = new SpecialPoint(SpecialPointConditionEnum.CLAY, 5, 1);
            var specialPoint3:SpecialPoint = new SpecialPoint(SpecialPointConditionEnum.CLAY, 7, 1);
            card.addSpecialPoint(specialPoint1);
            card.addSpecialPoint(specialPoint2);
            card.addSpecialPoint(specialPoint3);
            
            // Once at harvest time, can use 1 clay to get 2 foods
            var transformation:ResourceTransformation = new ResourceTransformation(ResourceTypeEnum.CLAY, ResourceTypeEnum.
                FOOD, 1, 2, 1);
            var possibleTransformations:ArrayCollection = new ArrayCollection();
            possibleTransformations.addItem(transformation);
            
            var action:ResourceTransformationAction = ActionFactory.getResourceTransformationAction(possibleTransformations);
            action.tempo = ActionTempoEnum.HARVEST;
            
            var actions:ArrayCollection = new ArrayCollection();
            actions.addItem(action);
            card.actions = actions;
            
            return card;
        }
    }
}